//
//  UIBarButtonItem+buttonItem.m
//  DQBaisibudejie
//
//  Created by 杜倩 on 16/8/30.
//  Copyright © 2016年 杜倩. All rights reserved.
//

#import "UIBarButtonItem+buttonItem.h"

@implementation UIBarButtonItem (buttonItem)

//高亮状态下的图片
+(UIBarButtonItem *)barButtonItemWith:(UIButton *)button addTarget:(id)target action:(SEL)selector andImage:(NSString *)imageName andhightLighted:(NSString *)hightlightedimage{
    
    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];//默认状态
    [button setImage:[UIImage imageNamed:hightlightedimage] forState:UIControlStateHighlighted];//高亮状态
    [button sizeToFit];//自动适应大小
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    //当把UIButton包装成UIBarButtonItem的时候单击的范围会自动扩大---恢复原样view包装button
    UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithCustomView:button];
    return item;
}

//设置选中状态下的图片
+(UIBarButtonItem *)barButtonItemWith:(UIButton *)button addTarget:(id)target action:(SEL)selector andImage:(NSString *)imageName andselectImage:(NSString *)selectimage{
    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];//默认状态
    [button setImage:[UIImage imageNamed:selectimage] forState:UIControlStateSelected];//高亮状态
    
    [button sizeToFit];//自动适应大小
    
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    return item;
}


@end
